<?	/*
	// File:	passwd.inc.phps
	// Purpose:	web-cp login screen, handle logout
	// Creation:	2005-11-03
	// Author:	pdrake
	*/

$username = load_input_vars('username');
$md5pass = load_input_vars('md5pass');

if (!empty($username)) {

	list($user, $userdomain) = explode('@', $username, 2);

	// Standardize Input
	$user = trim($user);

	// translate domain to ID
	$res = mysql_query('SELECT `id` FROM `domains` WHERE domain = "'.$userdomain.'" LIMIT 1') or print(mysql_error());
	list($domainid) = mysql_fetch_row($res);

	// Check user against database
	$userdata = fetchdata("id,password","user",Array($user, $domainid));

	// If the user is valid
	if ($userdata) {
		$domain = fetchdata("email","domain",$domainid);

		if ($domain)  {
			$msg = strtr($T['Pass Recovery Msg'], array(
				'{date}' => date($T['date_time_format']),
				'{ip}' => get_remote_ip(),
				'{password}' => $userdata['password'],
				));
			$success = mail($domain['email'],"web-cp ".$T['Password Recovery']." -- ".$username, $msg, "From: <".$cfg['adminmail'].">\n");

			send_header("Location: ".$web_name."/?data[failed]=recover");
			return;
		} else {
			$data['failed'] = "recover-failed";
		}
	} else {
		$data['failed'] = "recover-failed";
	}
}

// Show password recovery screen

?>

<div align="center"><br>
<?
		// If $data['failed'] is set (failed login), echo the error
		if (isset($data['failed'])) {
			echo "<p><center><font color='#990000'>";
			echo $T['err']['login'][$data['failed']];
			echo "</font></center></p>\n";
		}

		/*if (isset($success)) {
			echo "<p><center>";
			echo $T['password will be emailed'];
			echo "</center></p>\n";
			send_header("Location: ".$web_name."/");
			return;
		}*/
		// set salt for md5 (5 minute 'timer' to login)
		$utime = floor(time() / 300);
	?>
	<br>
	<form name="webcplogin" action="<?="./?cp=$cp&url=$url&number=$number&user=$user"; ?>" method="POST" onSubmit="submitonce(this); <? if (!$cfg['ssl']) echo "md5crypt('webcplogin','password','md5pass',$utime);" ?>">
	<table border="0" cellspacing="0" cellpadding="0" class="tblbg" width="300">
	<tr><td align="right">
	<table border="0" width="100%" cellspacing="1" width="300" cellpadding="1" >	<tr>
		<td class="tbltop"><b><?=$T['Password Recovery'];?></b></td>
	</tr>
	<tr>
		<td valign="top">
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content">
		<tr>
			<td align="right"><font size="1">
			<br>
			<div style="font-size:14px;"><?=$T['Username'];?>&nbsp;</div>
			<input type="text" name="username" size="35" maxlength="40" value="<? if ($username) echo $username;?>">&nbsp;<br>

            &nbsp;</font>
			</td>
		</tr>
		</table>
		</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<input type="hidden" value="" name="md5pass">
	<br>
        <center><input type="submit" value="<?=$T['Submit'];?>"><br><a href='index.php'>(<?=$T['cancel'];?>)</a></center></td>
	</form>
	<br><br>


</div>


